package net.vkits.api;

import io.swagger.annotations.ApiParam;
import net.vkits.anjiamiao.application.OrderApplicationService;
import net.vkits.anjiamiao.domain.model.Order;
import net.vkits.common.alipay.AlipayConfig;
import net.vkits.common.dto.SignDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;

/**
 * Created by ethan-liu on 2016/11/25.
 */
@Controller
public class PaymentApiController implements PaymentApi {
    private static final Logger logger = LoggerFactory.getLogger(PaymentApiController.class);

    @Resource
    private OrderApplicationService orderApplicationService;

    @Override
    public ResponseEntity<SignDTO> sign(@ApiParam(value = "订单ID", required = true) @RequestParam(value = "orderId") String orderId) {
        Order order = orderApplicationService.getOrder(orderId);
        String sign = AlipayConfig.sign(AlipayConfig.getOriginalContent(order.getId(), order.getOriginalOrder().getAmount()));
        SignDTO signDTO = new SignDTO();
        signDTO.setSign(AlipayConfig.getContent(sign, order.getId(), order.getOriginalOrder().getAmount()));
        return new ResponseEntity<>(signDTO, HttpStatus.OK);
    }
}
